<?php
session_start();
require('mysqlsettings.php');

		// Attempt to connect to MySQL and print out messages:
				$dbc = @mysql_connect($server, $username, $password);
				mysql_set_charset('utf8',$dbc);
				mysql_select_db('my_marks', $dbc);	
// if we haven log in as teacher then:				
if ( $_SESSION['estado'] == "teacher_login" ) {
//include the header
include("header.php");
		//if we select a group, then: 
		if (!empty($_SESSION['group'])){
		// create the HTML code where will appear the names of the students of the selected gorup
		
		echo "<br />";		
		echo "<table style='border-style:solid; text-align: center; border-width: thin; border-color:#910A2B; margin-left:20%;'>";
		echo "<tr><td><strong>Username</strong></td><td><strong>Name</strong></td><td><strong>First Surname</strong></td><td><strong>Group</strong></td><td><strong>Description</strong></td><td><strong>Date</strong></td><td><strong>Grade</strong></td></tr>";

									
		$var=$_SESSION['group'];	
		// It takes form the data base the names of the students of the selected group
		
		$query2 = "SELECT * FROM users INNER JOIN Marks ON users.Username = Marks.UserName WHERE users.Group ='$var'";
		$i=1;
		if ($r2 = mysql_query($query2, $dbc)) {
			while ($row = mysql_fetch_array($r2)) {
			echo "<tr><td id='Username$i'>{$row['Username']}</td><td>{$row['Name']}</td><td>{$row['First_Surname']}</td><td>{$row['Group']}</td><td style='width:300px;'>{$row['Description']}</td><td>{$row['Date']}</td><td><strong>{$row['Grade']}</strong></td></tr>";
			$i++;
			}	
		}
	
		echo "</table> <br/>";
		
		echo "<a href='ChooseGroup.php'>Return to Choose Group</a><br /><br />";

		
		}
		else{
			echo "<p style='color: red;'>Please, choose a group before continuing.</p>";
			echo "<br /><a href='ChooseGroup.php'>Return to Choose Group</a><br /><br />";
		}
	



}
else if (!empty($_SESSION['user'])){
// include the header
include("headerstudent.php");
		// crea la pagina de viewmarks que el alumno vera
		echo "<br />";
		echo "<table style='border-style:solid; text-align: center; border-width: thin; border-color:#910A2B; margin-left:20%;'>";
		echo "<tr><td><strong>Username</strong></td><td><strong>Name</strong></td><td><strong>First Surname</strong></td><td><strong>Group</strong></td><td><strong>Description</strong></td><td><strong>Date</strong></td><td><strong>Grade</strong></td></tr>";

									
		//It takes from the data base the marks of the loged student and put it in a variable
		$var=$_SESSION['user'];
		$query2 = "SELECT * FROM users INNER JOIN Marks ON users.Username = Marks.UserName WHERE Marks.UserName ='$var'";
		$i=1;
		// if the query is correct, the loop will generate a table with que marks of the student
		if ($r2 = mysql_query($query2, $dbc)) {
			while ($row = mysql_fetch_array($r2)) {
			echo "<tr><td id='Username$i'>{$row['Username']}</td><td>{$row['Name']}</td><td>{$row['First_Surname']}</td><td>{$row['Group']}</td><td style='width:300px;'>{$row['Description']}</td><td>{$row['Date']}</td><td><strong>{$row['Grade']}</strong></td></tr>";
			$i++;
			}	
		}
	
		echo "</table> <br/>";
}

else {

include("noacces.php");

}
//include the footer
include("footer.php");
?>